import pandas as pd 
dict = {
    'name':['Tom','Bob','Mary','James'],
    'age':[18,30,25,50],
    'city':['Beijing','Shanghai','Guangzhou','Shenzhen']
}
df = pd.DataFrame(dict)
print(df)

df['country'] = 'China'
print(df)

df['adress'] = df['city']+','+df['country']
print(df)

df.columns=['Age','City','Name','County','Address']


df['Group'] = 'elderly'
df.loc[df['Age']<=18,'Group'] = 'young'
df.loc[(df['Age']>18) & (df['Age']<=40),'Group'] = 'middle_age'
print(df)

print(df.loc[df['Age']>20])

print(df.loc[df['Group']=='middle_age'])

condition = df['Age']>25
result = df.where(condition)
print(result)
# result.dropna(inplace=True)
# print(result)


df.query('Group=="middle_aged"'and 'Age>30' )


print(df.shape)

print(df.describe())
df['Score'] = [100,87,99,61]
print(df.describe())

# 写CSV
df.to_csv('person.csv',index=None,sep=',')

# 读CSV
person = pd.read_csv('person.csv')
print(person)